package 贪心;

public class LeetCode1221_分割平衡字符串 {
    public int balancedStringSplit(String s) {
        int n = s.length();
        int balance = 0;
        int cnt = 0;
        for(int i = 0; i < n; i++) {
            if(s.charAt(i) == 'R') {
                --balance;
            }else if(s.charAt(i) == 'L') {
                ++balance;
            }
            if(balance == 0) {
                cnt ++;
            }
        }
        return cnt;
    }
}
